﻿@using JabbR
@using JabbR.ViewModels
@model ProfilePageViewModel

@{
    var userModel = Model;
    var gravatar = String.Format("https://secure.gravatar.com/avatar/{0}?s=48&d=mm", userModel.Hash);
    var passwordUrl = userModel.HasPassword ? Url.Content("~/account/changepassword") : Url.Content("~/account/newpassword");
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>JabbR</title>
    <link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Chat.css")" rel="stylesheet" />
</head>
<body>
    <section id="page" role="application">
        <header id="heading" role="heading">
            <div class="banner" role="banner">
                <h1>Jabb</h1>
                <div class="jabbrLogo" id="logo"></div>
                <div>
                    Powered by <a href="https://github.com/SignalR/SignalR" target="_blank">SignalR</a>
                </div>
            </div>
            <div style="clear: both"></div>
        </header>
        <div class="container">
            <div class="row" style="padding-top: 75px;">
                @Html.AlertMessages()
                <div class="span4 user-details-sidenav">
                    <div class="user-details">
                        <img class="gravatar" src="@gravatar" style="float: left;" />
                        <div class="details">
                            <span class="name">@userModel.Name</span>
                        </div>
                    </div>
                    <ul id="accountmenu" class="nav nav-list">
                        <li class="active"><a href="#profile" data-toggle="tab"><i class="icon-chevron-right"></i>Profile</a></li>
                        <li><a href="#changeUsername" data-toggle="tab"><i class="icon-chevron-right"></i>Username</a></li>
                        <li><a href="#changePassword" data-toggle="tab"><i class="icon-chevron-right"></i>Password</a></li>
                        @if(userModel.SocialDetails.ConfiguredProviders.Any())
                        {
                            <li><a href="#identityProviders" data-toggle="tab"><i class="icon-chevron-right"></i>Identity Providers</a></li>
                        }
                    </ul>
                </div>
                <div class="span8 tab-content">
                    <div class="account-details tab-pane active" id="profile">
                        <div class="account-details-header">
                            <h1>Profile</h1>
                        </div>
                        <div class="account-details-body">
                            <form class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label" for="note">Note</label>
                                    <div class="controls">
                                        <label class="control-label label-align-left">@(userModel.Note ?? "-")</label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="country">Country</label>
                                    <div class="controls">
                                        <label class="control-label label-align-left">@(userModel.Country ?? "-") <span class="flag flag-@userModel.Flag"></span></label>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="account-details tab-pane hide" id="changeUsername">
                        <div class="account-details-header">
                            <h1>Username</h1>
                        </div>
                        <div class="account-details-body">
                            <form class="form-horizontal" action="@Url.Content("~/account/changeusername")#changeUsername" method="POST">
                                @Html.ValidationSummary()
                                <div class="control-group">
                                    <label class="control-label" for="username">Username</label>
                                    <div class="controls">
                                        @Html.TextBox("username", "input-xlarge", "Username")
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="confirmUsername">Confirm Username</label>
                                    <div class="controls">
                                        @Html.TextBox("confirmUsername", "input-xlarge", "Confirm Username")
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input type="submit" class="btn" value="Change Username" />
                                    </div>
                                </div>
                                @Html.AntiForgeryToken()
                            </form>
                        </div>
                    </div>
                    <div class="account-details tab-pane hide" id="changePassword">
                        <div class="account-details-header">
                            <h1>Password</h1>
                        </div>
                        <div class="account-details-body">
                            <form class="form-horizontal" action="@passwordUrl#changePassword" method="POST">
                                @Html.ValidationSummary()
                                @if(userModel.HasPassword)
                                {
                                    <div class="control-group">
                                        <label class="control-label" for="oldPassword">Current Password</label>
                                        <div class="controls">
                                            @Html.Password("oldPassword", "input-xlarge", "Current Password")
                                        </div>
                                    </div>
                                }
                                <div class="control-group">
                                    <label class="control-label" for="password">Password</label>
                                    <div class="controls">
                                        @Html.Password("password", "input-xlarge", "Password")
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="confirmPassword">Confirm Password</label>
                                    <div class="controls">
                                        @Html.Password("confirmPassword", "input-xlarge", "Confirm Password")
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input type="submit" class="btn" value="Change Password" />
                                    </div>
                                </div>
                                @Html.AntiForgeryToken()
                            </form>
                        </div>
                    </div>
                    <div class="account-details tab-pane hide" id="identityProviders">
                        <div class="account-details-header">
                            <h1>Identity Providers</h1>
                        </div>
                        <div class="account-details-body">
                            @Html.Partial("_social", @userModel.SocialDetails)
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <script src="@Url.Content("~/Scripts/jquery-1.9.0.min.js")"></script>
    <script src="@Url.Content("~/Scripts/bootstrap.min.js")"></script>
    <script type="text/javascript">
        (function ($) {
            // set the selected tab based on the hash
            var currentSection = document.location.hash || "#profile";
            $('a[href="'+currentSection+'"]').tab('show');

            // always set the hash when we change tabs
            $('a[data-toggle="tab"]').on('shown', function(e) {
                document.location.hash = e.target.hash;
            });

            // make sure errors look pretty and bootstrap-y
            $('input.error').closest('.control-group').addClass('error');
        }(jQuery));
    </script>
</body>
</html>
